import tornado.httpserver
import tornado.ioloop
import tornado.web
from multiprocessing import Process
from log_config import logger_info, logger_error, logger_warning

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        # 记录INFO级别的日志
        logger_info.info("This is an info log")
        # 记录ERROR级别的日志
        logger_error.error("This is an error log")
        # 记录WARNING级别的日志
        logger_warning.warning("This is a warning log")
        self.write("Hello, Tornado!")

def start_tornado(port):
    app = tornado.web.Application([(r"/", MainHandler)])
    server = tornado.httpserver.HTTPServer(app)
    server.listen(port)
    tornado.ioloop.IOLoop.current().start()

if __name__ == "__main__":
    # 定义要使用的端口号列表
    ports = [8888, 8889, 8890]

    processes = []
    for i in ports:
        p = Process(target=start_tornado,args=(i,))
        p.start()
        processes.append(p)
    for p in processes:
        p.join()
# import logging
# import  tornado
# class LogFormatter(tornado.log.LogFormatter):
#     def __init__(self):
#         super(LogFormatter, self).__init__(
#             fmt='%(color)s[%(process)d %(asctime)s %(filename)s:%(funcName)s:%(lineno)d %(levelname)s]%(end_color)s  %(message)s',
#             datefmt='%Y-%m-%d %H:%M:%S'
#         )
# print(logging.getLogger().handlers)

# z=[i.setFormatter(LogFormatter()) for i in logging.getLogger().handlers]
# print("z===",z)





